package com.lhd.controller;

import com.lhd.pojo.PageBean;
import com.lhd.pojo.PageCondition;
import com.lhd.pojo.Result;
import com.lhd.pojo.Site;
import com.lhd.service.SiteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/site")
public class SiteController {
    @Autowired
    private SiteService siteService;
    @GetMapping("/all")
    public Result getAll(){
        List<Site> siteList = siteService.getAll();
        return Result.success(siteList);
    }
    @GetMapping("/condition")
    public Result getWithCondition(String name, Integer capacity, Integer curCapacity, String address, String phone, PageCondition pageCondition){
        PageBean<Site> pageBean = siteService.getWithCondition(name,capacity,curCapacity,address,phone,pageCondition);
        return Result.success(pageBean);
    }
    @PutMapping
    public Result updateSite(@RequestBody Site site){
        siteService.updateSite(site);
        return Result.success();
    }
    @DeleteMapping
    public Result delete(Integer id){
        siteService.remove(id);
        return Result.success();
    }
    @PostMapping
    public Result add(@RequestBody Site site){
        siteService.add(site);
        return Result.success();
    }
}
